package org.jmhome.blog.model;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@NamedQueries({
		@NamedQuery(name = "org.jmhome.blog.model.Board@BoardsInCategory", query = "from Board as board where category_id = :category order by boardSeq desc"),
		@NamedQuery(name = "org.jmhome.blog.model.Board@BoardsInEmail", query = "from Board as board where email = :email order by boardSeq desc"),
		@NamedQuery(name = "org.jmhome.blog.model.Board", query = "from Board as board where boardSeq = :boardSeq") })
public class Board {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer boardSeq;

	@ManyToOne
	@JoinColumn(name = "category_id")
	private Category category;

	@Column(length = 30)
	private String writer;

	private String title;

	@Lob
	@Column
	private String content;

	@Temporal(TemporalType.TIMESTAMP)
	private Date regDate;

	@OneToMany(targetEntity = BoardReply.class, mappedBy = "board", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@OrderBy("boardReplySeq asc")
	private List<BoardReply> boardReply;

	@OneToMany(targetEntity = AttachmentFile.class, mappedBy = "board", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@OrderBy("fileSeq desc")
	private List<AttachmentFile> attachmentFile;
	
	@OneToMany(targetEntity = BoardRecommandUser.class, mappedBy = "recommandBoard", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private List<BoardRecommandUser> recommandUser;

	@ManyToOne
	@JoinColumn(name = "email")
	private User user;

	private int count;

	public Board() {
		super();
	}

	public Board(String writer, String title, String content, Date regDate,
			User user, int count) {
		super();
		this.writer = writer;
		this.title = title;
		this.content = content;
		this.regDate = regDate;
		this.user = user;
		this.count = count;
	}

	/**
	 * @return the boardSeq
	 */
	public Integer getBoardSeq() {
		return boardSeq;
	}

	/**
	 * @param boardSeq
	 *            the boardSeq to set
	 */
	public void setBoardSeq(Integer boardSeq) {
		this.boardSeq = boardSeq;
	}

	/**
	 * @return the category
	 */
	public Category getCategory() {
		return category;
	}

	/**
	 * @param category
	 *            the category to set
	 */
	public void setCategory(Category category) {
		this.category = category;
	}

	/**
	 * @return the writer
	 */
	public String getWriter() {
		return writer;
	}

	/**
	 * @param writer
	 *            the writer to set
	 */
	public void setWriter(String writer) {
		this.writer = writer;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param title
	 *            the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}

	/**
	 * @param content
	 *            the content to set
	 */
	public void setContent(String content) {
		this.content = content;
	}

	/**
	 * @return the regDate
	 */
	public Date getRegDate() {
		return regDate;
	}

	/**
	 * @param regDate
	 *            the regDate to set
	 */
	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}

	/**
	 * @return the boardReply
	 */
	public List<BoardReply> getBoardReply() {
		return boardReply;
	}

	/**
	 * @param boardReply
	 *            the boardReply to set
	 */
	public void setBoardReply(List<BoardReply> boardReply) {
		this.boardReply = boardReply;
	}

	
	/**
	 * @return the attachmentFile
	 */
	public List<AttachmentFile> getAttachmentFile() {
		return attachmentFile;
	}

	/**
	 * @param attachmentFile the attachmentFile to set
	 */
	public void setAttachmentFile(List<AttachmentFile> attachmentFile) {
		this.attachmentFile = attachmentFile;
	}

	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}

	/**
	 * @param user
	 *            the user to set
	 */
	public void setUser(User user) {
		this.user = user;
	}

	/**
	 * @return the count
	 */
	public int getCount() {
		return count;
	}

	/**
	 * @param count
	 *            the count to set
	 */
	public void setCount(int count) {
		this.count = count;
	}

	/**
	 * @return the recommandUser
	 */
	public List<BoardRecommandUser> getRecommandUser() {
		return recommandUser;
	}

	/**
	 * @param recommandUser
	 *            the recommandUser to set
	 */
	public void setRecommandUser(List<BoardRecommandUser> recommandUser) {
		this.recommandUser = recommandUser;
	}
	
	

}
